package cn.kgc.springcloudfaqs.service.impl;

import cn.kgc.springcloudfaqs.FaqsVO;
import cn.kgc.springcloudfaqs.entity.Classes;
import cn.kgc.springcloudfaqs.entity.Faqs;
import cn.kgc.springcloudfaqs.mapper.FaqsMapper;
import cn.kgc.springcloudfaqs.service.ClassesService;
import cn.kgc.springcloudfaqs.service.FaqsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * InnoDB free: 8192 kB 服务实现类
 * </p>
 *
 * @author wulong
 * @since 2024-01-06
 */
@Service
public class FaqsServiceImpl extends ServiceImpl<FaqsMapper, Faqs> implements FaqsService {
    @Resource
    ClassesService classesService;
    @Resource
    RabbitTemplate rabbitTemplate;

    @Override
    public void saveFaqs(Faqs faqs) {
        faqs.setCreateDate(new Date());

        save(faqs);
        FaqsVO faqsVO = new FaqsVO();
        BeanUtils.copyProperties(faqs,faqsVO);

        Classes classes = classesService.getById(faqs.getClassId());
        faqsVO.setCname(classes.getCname());

        rabbitTemplate.convertAndSend("Exchange.direct","faqs",faqsVO);
    }
}
